using Android.Content;
using Java.Lang;
using System;

namespace SharpDepend.Android
{
    class EnviromentStatisticsManager : IEnviromentStatisticsManager
    {
        class EnviromentStatisticsClass : IEnviromentStatistics
        {
            private Context mContext;

            public EnviromentStatisticsClass(Context context)
            {
                this.mContext = context;
            }

            public long AppMemoryUsed
            {
                get
                {
                    return Runtime.GetRuntime().TotalMemory() - Runtime.GetRuntime().FreeMemory();
                }
            }

            public long TotalMemory
            {
                get
                {
                    return Runtime.GetRuntime().TotalMemory();
                }
            }

            public int CPUSpeed
            {
                get
                {
                    return -1;
                }
            }

            public int CPUProcessors
            {
                get
                {
                    return Environment.ProcessorCount;
                }
            }

            public string Device
            {
                get
                {
                    return global::Android.OS.Build.Manufacturer;
                }
            }

            public double ScaleFactor
            {
                get
                {
                    return mContext.Resources.DisplayMetrics.ScaledDensity;
                }
            }
        }

        private static EnviromentStatisticsClass mInstance;
        private Context mCcontext;

        public EnviromentStatisticsManager(Context context)
        {
            this.mCcontext = context;
        }

        public IEnviromentStatistics EnviromentStatistics
        {
            get
            {
                if (mInstance == null)
                {
                    mInstance = new EnviromentStatisticsClass(mCcontext);
                }

                return mInstance;
            }
        }
    }
}
